package thread;

/**
 * Created with IntelliJ IDEA.
 * Description: 主线程等待别的线程
 * User: 王圆豪
 * Date: 2025-04-26
 * Time: 18:38
 */
public class Demo16 {
    public static void main(String[] args) throws InterruptedException {
        Thread mainThread = Thread.currentThread();
        Thread thread = new Thread(()->{
            try {
                System.out.println("等待主线程......");
                mainThread.join();
                Thread.sleep(2000);
                System.out.println("thread线程结束！");
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        });

        thread.start();
        Thread.sleep(3000);
        System.out.println("主线程结束！");
    }
}
